package com.lixin.juc.forkjoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

public class MainApplication {

    public static void main(String[] args) {
        //testForkJoin();
        testSteam();
    }

    public static void testForkJoin() {
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        MyForkJoinTask myForkJoinTask = new MyForkJoinTask(0L, 10_0000_0000L);
        ForkJoinTask<Long> submit = forkJoinPool.submit(myForkJoinTask);
        try {
            Long sum = submit.get();
            System.out.println(sum);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }

    public static void testSteam() {
        long reduce = LongStream.rangeClosed(0L, 10_0000_0000L).parallel().reduce(0, Long::sum);
        System.out.println(reduce);
    }

}
